package pers.duorhs.csr.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.duorhs.common.socket.service.CsrSocketService;

/**
 * @author Duorhs
 * @date 2022/5/9 8:45
 */
@RestController
@RequestMapping("csr")
@Tag(name = "CSR")
@AllArgsConstructor
public class CsrController {
    private final CsrSocketService csrSocketService;

    @Operation(summary = "坐席登录")
    @PostMapping("login")
    public String login(@RequestParam String employee) {
        csrSocketService.employeeLogin(employee);
        return "OK:" + employee + "登录";
    }

    @Operation(summary = "推送Socket消息", description = "给坐席所关联的APP(前端)SocketClient推送消息")
    @PostMapping("push")
    public String push(@RequestParam String employee, @RequestParam String msg) {
        csrSocketService.push(employee, msg);
        return "OK:" + employee + "给APP端推送消息";
    }

    @Operation(summary = "坐席登出")
    @PostMapping("logout")
    public String logout(@RequestParam String employee) {
        csrSocketService.employeeLogout(employee);
        return "OK:" + employee + "登出";
    }

}
